<?php 
$this->load->view('admin/layout/head', array('title'=>'后台管理', 'nav' => 'product'), FALSE);
switch ($this->session->admin_language) {
	case 'chinese':
		$prefix = '';
		break;
	case 'english':
		$prefix = 'en_';
		break;
	default:
		$prefix = '';
		break;
}
?>

<div id="container">
	<form class="form-inline" id="search-form" method="GET" action="/admin/brand">
	  <div class="form-group">	   
	    <input type="text" name="keyword" placeholder="" class="form-control" style="width:300px" placeholder="">
	  </div>
	  <a href="javascript:;" class="btn btn-info search-btn"><?= $this->lang->line('search') ?></a>
	 <a href="/admin/brand/create" class="btn btn-default add-btn"><span class="glyphicon glyphicon-plus"></span> <?= $this->lang->line('create') ?></a>
	</form>


	<table class="table table-bordered table-striped table-hover scroll-table mt-20">
		<thead>
			<tr>
				<th width="100" class="text-center"><?= $this->lang->line('brand_name') ?></th>
				<th width="240" class="text-center"><?= $this->lang->line('brand_image') ?></th>
				<th width="60" class="text-center"><?= $this->lang->line('sort') ?></th>
				<th width="80" class="text-center"><?= $this->lang->line('actions') ?></th>
			</tr>
		</thead>
		<tbody>
			<?php foreach ($page->data() as $key => $value): ?>
				<tr>
					<td><?= $value[$prefix.'title'] ?></td>
					<td>
						<img src="<?= $value['image'] ?>" style="max-height: 60px; max-width: 200px" alt="image">
					</td>
					<td>
						<?= $value['sort'] ?>
					</td>
					<td data-id="<?= $value['id'] ?>">
						<a href="<?= site_url("admin/brand/edit/{$value['id']}") ?>" class="modify-btn"><?= $this->lang->line('edit'); ?></a>
						<a href="javascript:;" class="del-btn"><?= $this->lang->line('delete') ?></a>
					</td>
				</tr>
			<?php endforeach ?>
		</tbody>
		<?php 
			if($page->last_page>1){
				//$products->url = current_url();
			?>
			<tfoot>
				<td colspan="4" style="text-align:right">
					<?php echo $page->render() ?>
				</td>
			</tfoot>
			<?php 
			}
			?>
	</table>
</div>

<?php 
$this->load->view('admin/layout/footer');
?>

<script>
$(function () {
	// 删除
	$('.del-btn').on('click', function () {
		var td = $(this).parents('td');
		var id = td.attr('data-id');
		$.getJSON('/admin/brand/delete/'+id, function (json) {
			Toast.success('删除成功', function () {
				td.parents('tr').fadeOut('fast', function () {
					td.parents('tr').remove();
				});
			});
		});
	});

	$('.search-btn').on('click',function(){
		$('#search-form').submit();
	})
});
</script>